package com.example.photography.Activity.message;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.photography.R;
import com.example.photography.adapter.message.MessageAdapter;
import com.example.photography.bean.MessagesBean;
import com.example.photography.common.BaseActivity;
import com.example.photography.util.Util;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 赞和收藏
 */
public class Message_like_and_save extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.lv_message)
    ListView lvMessage;
    private List<MessagesBean> messagesBeans;
    private MessageAdapter messageAdapter;

    @Override
    protected void initData() {

        String content = Util.getJson(this, "like_and_save.json");
        if (TextUtils.isEmpty(content)) {//数据为空
            return;
        }
        JSONObject jsonObject = JSON.parseObject(content);
        int status = jsonObject.getInteger("code");
        if (status == 202) {
            String data = jsonObject.getString("data");
            String message = JSON.parseObject(data).getString("message");
            //封装转json数据
            messagesBeans = JSONObject.parseArray(message, MessagesBean.class);
            initView();
        } else {
            // TODO: 2021/5/2 加没数据的判断
        }
    }

    private void initView() {
        tvTitle.setText("赞和关注");
        messageAdapter = new MessageAdapter(messagesBeans,this);
        lvMessage.setAdapter(messageAdapter);
        initListen();
    }

    private void initListen() {
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                removeCurrentActivity();
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.message_like_and_save;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}